/api/user-data trusts an x-wallet-address header - #10
Merged
P3az3 merged 2 commits intoAug 24, 2026
Merged
Conversation
/api/user-data trusts an x-wallet-address header
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR secures the
/api/user-dataendpoint and replaces the race-prone file-based user data store with durable server-side storage.Previously, the API trusted the client-supplied
x-wallet-addressheader as the user's identity. This allowed any client to access, modify, or delete another user's data by providing their wallet address. User data was also stored in a single JSON file, where concurrent read-modify-write operations could overwrite each other's changes.This change derives the wallet address from a verified authentication token and moves user data to a durable storage backend while preserving the existing
UserDataSnapshotshape.Changes
GET,PUT, andDELETE /api/user-data.walletAddressclaim instead of trustingx-wallet-address.x-wallet-addressheaders when an authenticated identity is present.UserDataSnapshotstructure to avoid unnecessary changes to consumers.Security
The previous implementation allowed requests such as:
to access another user's data.
The API now requires a valid token and derives the wallet address from the authenticated identity. The client can no longer select which user's data to access simply by changing a request header.
Testing
Verified unauthenticated
GET,PUT, andDELETErequests are rejected.Verified an authenticated user can access their own data.
Verified a client cannot access another wallet's data by modifying
x-wallet-address.Verified a forged
x-wallet-addressis ignored when a valid authenticated identity is present.Verified user data persists across application restarts.
Verified concurrent saves do not silently discard updates.
Ran:
npm run type-checknpm run lintFiles Changed
app/api/user-data/route.tslib/server/userDataStore.tslib/api/userData.tshooks/useUserDataSync.tsAcceptance Criteria
x-wallet-addresscannot be used to impersonate another user.UserDataSnapshotconsumers continue to work.Closes #4